//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#ifndef __ELASTOS_ATOMIC_H__
#define __ELASTOS_ATOMIC_H__

#if     KCONFIG_SMP
#define __LOCK  "lock;"
#else
#define __LOCK  ""
#endif

INLINE void AtomicIncrement(Int32 *pDestOperand)
{
    ASM(__LOCK
        "incl   %0;"
        :"=m"(*pDestOperand) :"m"(*pDestOperand));
}

INLINE void AtomicDecrement(Int32 *pDestOperand)
{
    ASM(__LOCK
        "decl   %0;"
        :"=m"(*pDestOperand) :"m"(*pDestOperand));
}

INLINE void AtomicAdd(Int32 *pDestOperand, Int32 srcOperand)
{
    ASM(__LOCK
        "addl   %1, %0;"
        :"=m"(*pDestOperand) :"ir"(srcOperand), "m"(*pDestOperand));
}

INLINE void AtomicSub(Int32 *pDestOperand, Int32 srcOperand)
{
    ASM(__LOCK
        "subl   %1, %0;"
        :"=m"(*pDestOperand) :"ir"(srcOperand), "m"(*pDestOperand));
}

INLINE void AtomicAnd(Int32 *pDestOperand, Int32 srcOperand)
{
    ASM(__LOCK
        "andl   %1, %0;"
        :"=m"(*pDestOperand) :"ir"(srcOperand), "m"(*pDestOperand));
}

INLINE void AtomicOr(Int32 *pDestOperand, Int32 srcOperand)
{
    ASM(__LOCK
        "orl    %1, %0;"
        :"=m"(*pDestOperand) :"ir"(srcOperand), "m"(*pDestOperand));
}

#endif //__ELASTOS_ATOMIC_H__
